import {
	mapState,
} from 'vuex'
import api from '@/service/config/api.js'
export default {
	data() {
		return {
			userInfo: this.$storage.getItem('basicUnserInfo') || {},
			ossUrl: this.$ossUrl,
			basicUnserInfo: {},
			requestCount: 0
		}
	},
	computed: {
		...mapState(['userType']),
		permission() {
			if(this.$store.state.appType==this.$base.USER_TYPE||!this.$storage.getItem('token')){
				return true
			}
			return this.$store.state.userType != 3 || (this.$store.state.userType == 3 && this.basicUnserInfo.dealerAuditStatus == 2 && this
				.basicUnserInfo
				.paySetMeal)
		},
		checkToken() {
			return !!this.$storage.getItem('token')
		}
	},
	onShow() {
		if(!!this.$storage.getItem('token'))
			this.getBasicUserInfo()
	},
	methods: {
		getBasicUserInfo() {
			api.get("/user/api/auth/userInfo").then((res) => {
				console.log("用户信息1");
				console.log(res);
				if (res && res.code == 0) {
					this.requestCount = 1

					const data = res.data
					let userType = data.identityType

					if (data.identityType == 1) {
						if(data.dealer) {
							this.$storage.setItem("userType", 3);
							userType = 3
						} else if (!data.manager && !data.guide && !data.dealer) {

							this.$storage.setItem("userType", 4);
							userType = 4
						} else if (data.manager) {
							this.$storage.setItem("userType", 2);
							userType = 2

						} else if (data.guide) {
							this.$storage.setItem("userType", 1);
							userType = 1

						}

					} else if (data.identityType == 2) {
						this.$storage.setItem("userType", 3);
						userType = 3
					} else {
						this.$storage.setItem("userType", data.identityType + 2);
						userType = data.identityType + 2
					}
					this.$store.commit('setUserType', userType)
					if (data) {
						this.basicUnserInfo = data
						this.$storage.setItem("basicUnserInfo", data)
						this.$store.commit('setUserInfo', data)
					}
				}
			});
		},
	}
}